clear all; clc; close all;

TxParam.Fs = 3759398496.2406; 
TxParam.numSubcarriers = 128;
TxParam.packetSeparationDuration = 0; %1e-3;
TxParam.numOfdmBlocks = 1;
TxParam.GI_type = 'zeros';
TxParam.GI_sizePct = 0;

TxParam.PilotModType = 'QAM16';
TxParam.PilotModBand = 1:1:TxParam.numSubcarriers;
TxParam.PilotModData = randi([0 1], 1, length(TxParam.PilotModBand)); %[1,1,1,1,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,1,0,0,0,1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,1,1,1,0,0,1,1,0,0,1,1,0,1,1,1,0,1,0,0,1,1]; %randi([0 1], 1, length(TxParam.PilotModBand));
TxParam.NullModBand = [];
TxParam.ActiveModType = 'QAM16';
TxParam.ActiveModBand = setdiff(2:TxParam.numSubcarriers, TxParam.PilotModBand);

transmitter = C_Tx();
transmitter.Initialise(TxParam);

%--------------------------------------------------------------------------

% ---common param---
ChannelParam.EbPerNo = 0:10:40;

OptChn = C_OpticalChannel.Instance(transmitter);
OptChn.Initialise(OptChn, ChannelParam);

%--------------------------------------------------------------------------      

RxParam.Fs = TxParam.Fs;
RxParam.ToffsetPct = 0;
RxParam.FoffsetPct = 0;

RxParam.ActiveModType = TxParam.ActiveModType;
RxParam.ActiveModBand = TxParam.ActiveModBand;
RxParam.PilotModType = TxParam.PilotModType;
RxParam.PilotModBand = TxParam.PilotModBand;
RxParam.NullModBand = TxParam.NullModBand;

receiver = C_Rx(transmitter, OptChn);
receiver.Initialise(RxParam);

%--------------------------------------------------------------------------

evaluate = C_Eval.Instance(transmitter, receiver, OptChn);
evaluate.Initialise(evaluate);

%--------------------------------------------------------------------------    

Iteration = 1;
for IterationIndex = 1:Iteration
    clc; IterationIndex

    transmitter.Generate();
    TxSignal = transmitter.GetTxSignal;
    RxSignal = OptChn.AddChannelResponse(OptChn, TxSignal);
    receiver.Decode(RxSignal);
    evaluate.Eval(evaluate);
end

evaluate.DisplayErrorRate(evaluate);
% evaluate.SaveErrorRate(evaluate);

